import {
    graphql,
    GraphQLSchema,
    GraphQLObjectType,
    GraphQLString,
} from 'graphql';

var schema = new GraphQLSchema({
    query: new GraphQLObjectType({
        name: 'RootQueryType',
        fields: {
            hello: {
                type: GraphQLString,
                resolve() {
                    return 'world';
                },
            },
        },
    }),
});

const source = '{ hello }';

graphql({ schema, source }).then((result) => {
    console.log('result:', result);
    console.log(JSON.stringify(result));
});

const source2 = '{ BoyHowdy }';
graphql({ schema, source2 }).then((result) => {
    console.log('error in BoyHowdy', result.errors?.[0]?.message);
    console.log(JSON.stringify(result));
});
